/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-12-27 09:29:57
 * @LastEditors: 商晓彬
 * @LastEditTime: 2022-01-04 14:25:48
 */
import { Component, Injector, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { ProductionReviewServiceProxy,CommonServiceProxy ,RocketProjectBoardServiceProxy,RocketProjectReportData} from '@shared/service-proxies/service-proxies';
import * as moment from 'moment';
import { LazyLoadEvent, TreeNode } from 'primeng/api';

@Component({
  selector: 'app-plan-kanban',
  templateUrl: './plan-kanban.component.html',
  styleUrls: ['./plan-kanban.component.less']
})
export class PlanKanbanComponent extends AppComponentBase {

    constructor(
        injector: Injector,
        private _messageService: MessageService,
        private _productionReviewServiceProxy: ProductionReviewServiceProxy,
        private _commonServiceProxy: CommonServiceProxy,
        private _rocketProjectBoardServiceProxy: RocketProjectBoardServiceProxy,
    ) {
        super(injector);
    }
    date: any;
    week: any;
    time: any;
    timer: any;
    fullScreen = false;
    model = undefined;
    modelOptions = [
        {
            label: '请选择型号',
            value: undefined
        }
    ];
    sendTime = undefined;
    sendTimeOptions = [
        {
            label: '请选择发次',
            value: undefined
        }
    ];
    stuts = new RocketProjectReportData();
    tableData = [];
    visiable = true;
    getIntervalData() {
        //型号
        this._commonServiceProxy.getModelList(
            )
                .pipe(finalize(() => { })).subscribe(result => {
                    for (const item of result) {
                        let data = { label: undefined, value: undefined };
                        data.label = item.label;
                        data.value = item.value;
                        this.modelOptions.push(data);
                    }
                    this.model = this.modelOptions[1].value;
                    this._commonServiceProxy.getLotNoList(
                        this.model
                    )
                        .pipe(finalize(() => { })).subscribe(result => {
                            for (const item of result) {
                                let data = { label: undefined, value: undefined };
                                data.label = item.label;
                                data.value = item.value;
                                this.sendTimeOptions.push(data);
                            }
                            this.sendTime = this.sendTimeOptions[1].value;
                            this.search();
                        })
                })
    }
    ngOnInit() {
        this.getIntervalData();
        setInterval(() => {
            this.search();
        }, 3600000);
    }
    search() {
        this.visiable = false;
        //表格数据
        this._rocketProjectBoardServiceProxy.getRocketProjectReportList(
            this.model,
            this.sendTime,
            )
            .pipe(finalize(() => { })).subscribe(result => {
                this.visiable = true;
                this.stuts = result.data;
                this.tableData = result.children;
                // this.expandAll();
            })
    }
    expandAll() {
        for (const node of this.tableData) {
            this.TreeExpandRecursive(node, true);
        }
    }
    private TreeExpandRecursive(node: TreeNode, isExpand: boolean) {
        node.expanded = isExpand;
        if (node.children) {
            node.children.forEach((childNode) => {
                this.TreeExpandRecursive(childNode, isExpand);
            });
        }
    }
    onchange(event) {
        this. sendTimeOptions = [
            {
                label: '请选择发次',
                value: undefined
            }
        ];
        //发次
        this._commonServiceProxy.getLotNoList(
            this.model
        )
            .pipe(finalize(() => { })).subscribe(result => {
                for (const item of result) {
                    let data = { label: undefined, value: undefined };
                    data.label = item.label;
                    data.value = item.value;
                    this.sendTimeOptions.push(data);
                }
            })
    }
    full() {
        if (!this.fullScreen) {
            this.search();
            const docElmWithBrowsersFullScreenFunctions = document.getElementById('main') as HTMLElement & {
                webkitRequestFullscreen(): Promise<void>;
            };
            if (docElmWithBrowsersFullScreenFunctions.requestFullscreen) {
                docElmWithBrowsersFullScreenFunctions.requestFullscreen();
            } else if (docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen) { /* Chrome, Safari and Opera */
                docElmWithBrowsersFullScreenFunctions.webkitRequestFullscreen();
            }
            this.fullScreen = true;
        } else {
            this.search();
            const docWithBrowsersExitFunctions = document as Document & {
                webkitExitFullscreen(): Promise<void>;
            };
            if (docWithBrowsersExitFunctions.exitFullscreen) {
                docWithBrowsersExitFunctions.exitFullscreen();
            } else if (docWithBrowsersExitFunctions.webkitExitFullscreen) { /* Chrome, Safari and Opera */
                docWithBrowsersExitFunctions.webkitExitFullscreen();
            }
            this.fullScreen = false;
        }
    }
    ngAfterContentChecked() {
        //渲染完成后
        this.getNowDate();
        if (this.timer) {
        } else {
            this.timer = setInterval(this.getNowDate, 1000);
        }
    }
    getNowDate() {
        let nowDate = new Date();
        this.date = moment(nowDate).format('YYYY-MM-DD');
        var a = ["日", "一", "二", "三", "四", "五", "六"];
        var week = new Date().getDay();
        this.week = "星期" + a[week];
        this.time = moment(nowDate).format('HH:mm:ss');
    }

}
